//
// Description: 6038. 向表达式添加括号后的最小结果
// Created by Loading on 2022/4/10.
//

#include <bits/stdc++.h>

using namespace std;

string minimizeResult(string expression) {
    int index = expression.find('+');
    // "+" 左侧和右侧分离
    string s1 = expression.substr(0, index);
    string s2 = expression.substr(index + 1);

    string res;
    int num_res = INT_MAX;
    // 暴力枚举所有括号的情况
    for (int i = 0; i < s1.size(); ++i) {
        for (int j = 0; j < s2.size(); ++j) {
            // 组合添加括号的字符串，注意截取字符串时的参数
            string tmp = s1.substr(0, i) + "(" + s1.substr(i) + "+" + s2.substr(0, j + 1) + ")" + s2.substr(j + 1);
            // 提取添加括号后的四个数值
            int n1 = 1;
            if (i != 0) {
                n1 = stoi(s1.substr(0, i));
            }
            int n2 = stoi(s1.substr(i));
            int n3 = stoi(s2.substr(0, j + 1));
            int n4 = 1;
            if (j != s2.size() - 1) {
                n4 = stoi(s2.substr(j + 1));
            }
            // 计算当前情况的结果
            if (n1 * (n2 + n3) * n4 < num_res) {
                num_res = n1 * (n2 + n3) * n4;
                res = tmp;
            }
        }
    }

    return res;
}

int main() {
    string expression = "12+34";
    auto res = minimizeResult(expression);
    cout << res << endl;

    return 0;
}